﻿//
// Code coverage testing.
//

using Kw.Data;
using System;
using System.Collections.Generic;
using System.Threading;

namespace KwDataBench
{
    class BtreeBench04
    {
        static void Main ()
        {
            var tree1 = new BtreeDictionary<int, int> (5);

            for (int k = 0; k < 99; k += 8)
                tree1.Add (k, k + 100);

            tree1.Dump ();

            // Cause leaf split with rightside insert.
            Console.WriteLine ();
            Console.WriteLine ("++ 20");
            tree1.Add (20, 1);
            tree1.Dump ();

            // Cause leaf split with rightside insert, cascade promote.
            Console.WriteLine ();
            Console.WriteLine ("++ 50");
            tree1.Add (50, 1);
            tree1.Dump ();

            Console.WriteLine ();
            Console.WriteLine ("++ 66");
            tree1.Add (66, 132);
            tree1.Dump ();

            // Cause leaf join, branch shift.
            Console.WriteLine ();
            Console.WriteLine ("-- 20");
            tree1.Remove (20);
            tree1.Dump ();

            Console.WriteLine ();
            Console.WriteLine ("++ 38");
            tree1.Add (38, 147);
            tree1.Dump ();

            Console.WriteLine ();
            Console.WriteLine ("++ 35,12");
            tree1.Add (35, 142);
            tree1.Add (12, 142);
            tree1.Dump ();

            // Cause leaf split with leftside insert.
            Console.WriteLine ();
            Console.WriteLine ("++ 10");
            tree1.Add (10, 147);
            tree1.Dump ();

            // Cause leaf split with rightside pair insert, cascade promote.
            Console.WriteLine ();
            Console.WriteLine ("++ 36");
            tree1.Add (36, 147);
            tree1.Dump ();

            // Cause branch join with leftside key delete.
            Console.WriteLine ();
            Console.WriteLine ("-- 12");
            tree1.Remove (12);
            tree1.Dump ();

            Console.WriteLine ();
            Console.WriteLine ("-- 8");
            tree1.Remove (8);
            tree1.Dump ();

            // Cause leaf shift.
            Console.WriteLine ();
            Console.WriteLine ("-- 10");
            tree1.Remove (10);
            tree1.Dump ();

            Console.WriteLine ();
            Console.WriteLine ("-- 88");
            tree1.Remove (88);
            tree1.Dump ();

            Console.WriteLine ();
            Console.WriteLine ("-- 56");
            tree1.Remove (56);
            tree1.Dump ();

            // Cause cascade delete of rightmost branch.
            Console.WriteLine ();
            Console.WriteLine ("-- 80");
            tree1.Remove (80);
            tree1.Dump ();

            // Cause prune of root.
            Console.WriteLine ();
            Console.WriteLine ("-- 96");
            tree1.Remove (96);
            tree1.Dump ();

            Console.WriteLine ();
            Console.WriteLine ("++ 18");
            tree1.Add (18, 118);
            tree1.Dump ();

            Console.WriteLine ();
            Console.WriteLine ("++ 11");
            tree1.Add (11, 111);
            tree1.Dump ();
        }
    }
}
